<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('内外线交货单列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>

                            <li>
                                <label>交货：</label>
                                <input type="text" name="VBELN"  style="width: 130px;"/>
                            </li>
                            <li>
                                <label>交货项目：</label>
                                <input type="text" name="POSNR" style="width: 130px;"/>
                            </li>
                            <li>
                                <label>物料：</label>
                                <input type="text" name="MATNR" style="width: 130px;"/>
                            </li>

                            <li>
                                <label>库存地点：</label>
                                <input type="text" name="LGORT" style="width: 130px;"/>
                            </li>
                            <li>
                                <label>批次：</label>
                                <input type="text" name="CHARG" style="width: 130px;"/>
                            </li>
                            <li>
                                <label>状态：</label>
                                <select name="status" style="width: 130px;" th:with="type=${@dict.getType('DN_POST_DN_status')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>

                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="zflWmsDnPostDn:ZflWmsDnPostDn:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="changeStatus(0)">
                    <i class="fa fa-edit"></i> 重新过账
                </a>
                <a class="btn btn-warning single disabled" onclick="changeStatus(3)">
                    <i class="fa fa-edit"></i> 重新质检
                </a>
<!--                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zflWmsDnPostDn:ZflWmsDnPostDn:remove">-->
<!--                    <i class="fa fa-remove"></i> 删除-->
<!--                </a>-->
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zflWmsDnPostDn:ZflWmsDnPostDn:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
            </div>
            <div id="div" class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('zflWmsDnPostDn:ZflWmsDnPostDn:edit')}]];
        var removeFlag = [[${@permission.hasPermi('zflWmsDnPostDn:ZflWmsDnPostDn:remove')}]];
        var DNstatus = [[${@dict.getType('DN_POST_DN_status')}]];
        var ZJ_status = [[${@dict.getType('ZJ_status')}]];
        var prefix = ctx + "DN_POST_DN/DN_POST_DN";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                // updateUrl: prefix + "/edit?",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                singleSelect:true,
                height: $("#div").height() / 1,
                modalName: "内外线交货单",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'zeile',
                    title: '行项目编号',
                    sortable: true
                },
                {
                    field: 'vbeln',
                    title: '交货'
                },
                {
                    field: 'posnr',
                    title: '交货项目'
                },
                {
                    field: 'matnr',
                    title: '物料'
                },
                {
                    field: 'lfimg',
                    title: '交货数量'
                },
                {
                    field: 'pikmg',
                    title: '拣配数量'
                },
                {
                    field: 'werks',
                    title: '工厂'
                },
                {
                    field: 'lgort',
                    title: '库存地点'
                },
                {
                    field: 'charg',
                    title: '批次'
                },
                {
                    field: 'vrkme',
                    title: '单位'
                },
                {
                    field: 'sernr',
                    title: '序列号'
                }, {
                    field: 'mblnr',
                    title: '物料凭证编号'
                },{
                    field: 'vbelp',
                    title: '交货项目',
                    visible: false
                },{
                    field: 'mjahr',
                    title: '物料凭证年度'
                },{
                    field: 'prueflos',
                    title: '检验批编号'
                },{
                    field: 'type',
                    title: '质检结果',
                        formatter: function(value, item, index) {
                            return $.table.selectDictLabel(ZJ_status,value);
                        }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, item, index) {
                        return $.table.selectDictLabel(DNstatus,value);
                    }
                },
                {
                    field: 'error',
                    title: '错误信息'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.ZEILE + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.sernr + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }
                ]
            };
            $.table.init(options);
        });

        function changeStatus(newStatus){
                var row = $("#bootstrap-table").bootstrapTable('getSelections')[0];
            if ($.common.isEmpty(row)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
                if (newStatus == 0 ){
                    if (row.status != 2){
                        $.modal.alertWarning("只能对【过账失败】单据重新过账！");
                        return;
                    }
                }
                if (newStatus == 3 ){
                    if (row.status != 4){
                        $.modal.alertWarning("只能对【质检失败】单据重新质检！");
                        return;
                    }
                }

            $.post(prefix + "/editStatus", {ZEILE:row.zeile, VBELN: row.vbeln,status: newStatus}, function(result) {
                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("操作成功！")
                } else {
                    $.modal.msgError(result.msg);
                }
            });
        }
    </script>
</body>
</html>